import { ActionTree, GetterTree, MutationTree } from 'vuex'
import { router } from '../routers'
// @ts-ignore

const currentRoutesMap = router.options.routes[0].children

interface BreadMap {
  name: string
  path: string
  children?: BreadMap
}

class State {
  public bread: BreadMap = {
    name: '',
    path: ''
  }
}

const mutations = {
  makeBreadList (state, that) {
    let matched1 = that.$route.matched[1] || {}
    let matched2 = that.$route.matched[2] || {}
    state.bread = {
      name: matched1.name,
      path: matched1.path,
      children: {
        name: matched2.name,
        path: matched2.path
      }
    }
  }
} as MutationTree<State>
const actions = {} as ActionTree<State, any>
const getters = {
  BreadMap (state: State) {
    return state.bread
  }
} as GetterTree<State, any>
const bread = {
  namespace: true,
  state: new State(),
  mutations,
  actions,
  getters
}
export default bread
